#pragma once
#include "../sync/lock.h"
#include <list>

namespace qb{
namespace base{
	template<class T>
	class SyncPtrQueue{
		Spinlock			m_lock;
		std::list<T*>		m_pointers;			// later use a cumstomized allocator
	public:
		SyncPtrQueue(){}
	//	SyncPtrQueue(int spinCount):m_lock(spinCount){}
		~SyncPtrQueue(){}
		void Add(T* ptr)
		{
			ScopedLock<Spinlock> scoped(m_lock);
			m_pointers.push_back(ptr);
		}
		T* Pick()
		{
			T* ptr = 0;
			ScopedLock<Spinlock> scoped(m_lock);
			if(!m_pointers.empty())
			{
				ptr = m_pointers.front();
				m_pointers.pop_front();
			}
			return ptr;
		}
		int  Size()
		{
			ScopedLock<Spinlock> scoped(m_lock);
			return m_pointers.size();
		}
	};
}//namespace base;
}//namespace ss;